using System.Windows.Forms;
using ICSharpCode.TextEditor.Actions;
using ICSharpCode.TextEditor.UserControls;

namespace ICSharpCode.TextEditor.Src.Actions
{
	internal class GoToLineNumberAction : AbstractEditAction
	{
		private readonly GotoForm _gotoForm;

		public GoToLineNumberAction()
		{
			this._gotoForm = new GotoForm();
		}

		public override void Execute(TextArea textArea)
		{
			this._gotoForm.FirstLineNumber = 1;
			this._gotoForm.LastLineNumber = textArea.Document.TotalNumberOfLines;
			this._gotoForm.SelectedLineNumber = textArea.Caret.Line + 1;
			if (DialogResult.OK == this._gotoForm.ShowDialogEx() && this._gotoForm.SelectedLineNumber > 0)
			{
				textArea.Caret.Position = new TextLocation(0, this._gotoForm.SelectedLineNumber - 1);
			}
		}
	}
}
